// 蜂窝蜜造平台生成代码，此文件只生成一次，不需要添加到 .beeignore

package com.fowo.api.service.impl.IssuOrderPlatformService;

import cn.hutool.core.exceptions.ExceptionUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONObject;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.fowo.api.common.model.R;
import com.fowo.api.datainterface.service.impl.DatainterfaceServiceImpl;
import com.fowo.api.entity.IssuOrder;
import com.fowo.api.model.issu.order.IssuOrderVo;
import com.fowo.api.model.nav.sell.order.NavSellOrderVo;
import com.fowo.api.service.IssuOrderPlatformService;
import com.fowo.api.shein.service.SheinOrderApiService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * 订单管理订单标发 服务实现类
 */
@Service
@Slf4j
@DS("ds24")
public class IssuOrderSheinServiceImpl implements IssuOrderPlatformService {
    @Resource
    private DatainterfaceServiceImpl datainterfaceService;
    @Resource
    private SheinOrderApiService sheinOrderApiService;


    public String getType() {
        return "Shein";
    }

    /**
     * 标发
     *
     * @param navSellOrderVo
     * @return
     */
    public R markIssu(NavSellOrderVo navSellOrderVo) {
        try {
            JSONObject resultObject = sheinOrderApiService.confirmShipping(navSellOrderVo.getShopInfo(), null, navSellOrderVo.getPlatform().get(0).getPlatformOrderId());
            Integer code = resultObject.getInt("code");
            if (code == 0) {
                return R.ok(true);
            } else {
                return R.fail(resultObject.getStr("msg"));
            }
        } catch (Exception ex) {
            return R.fail(StrUtil.format("执行标发单:{}发生异常,详情:{}", navSellOrderVo.getOrderId(), StrUtil.subPre(ExceptionUtil.getRootCauseMessage(ex), 2000)));
        }
    }

    /**
     * 同步标发结果
     *
     * @param issuOrder
     * @return
     */
    public R syncIssu(IssuOrderVo issuOrder) {
        return R.ok(true);
    }
}
